package cn.liulingfengyu.behavioralpatterns.mediatorpattern;

public class MediatorPatternDemo {
    public static void main(String[] args) {
        // 创建中介者
        Mediator mediator = new ConcreteMediator();

        // 创建同事类
        Colleague colleagueA = new ConcreteColleagueA(mediator);
        Colleague colleagueB = new ConcreteColleagueB(mediator);

        // 将同事类注册到中介者
        ((ConcreteMediator) mediator).addColleague(colleagueA);
        ((ConcreteMediator) mediator).addColleague(colleagueB);

        // 同事A发送消息
        colleagueA.sendMessage("你好，我是A");

        // 同事B发送消息
        colleagueB.sendMessage("你好，我是B");
    }
}